<?php

class Location {
    const EARTH_RADIUS = 6371;

    /*
     * http://en.wikipedia.org/wiki/Great-circle_distance
     * */
    public static function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {
        $dist = acos(
              cos(deg2rad($latitude1))
            * cos(deg2rad($latitude2))
            * cos(deg2rad($longitude1) - deg2rad($longitude2))
            + sin(deg2rad($latitude1))
            * sin(deg2rad($latitude2))
          );
          return round($dist * self::EARTH_RADIUS, 3);
    }
}
